package com.hucheng.goods;

import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration;
import com.hucheng.common.config.aspect.DynamicDataSourceAspect;
import com.hucheng.common.config.db.DynamicDataSourceRegister;
import com.hucheng.goods.utils.HtmlTemplateUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@SpringBootApplication
@EnableDubboConfiguration
@EnableTransactionManagement
@Import(value = {DynamicDataSourceRegister.class, DynamicDataSourceAspect.class})
public class DubboGoodsProviderApplication {

    public static void main(String[] args) throws IOException {
        SpringApplication.run(DubboGoodsProviderApplication.class, args);
        test();
    }

    public static void test() throws IOException {
        String template = "<!DOCTYPE html>\n" +
                "<html lang=\"en\">\n" +
                "<head>\n" +
                "    <meta charset=\"UTF-8\">\n" +
                "    <title>Title</title>\n" +
                "</head>\n" +
                "<body>\n" +
                "    <h1 th:text=\"${name}\">列表名称</h1>\n" +
                "    <ul>\n" +
                "        <li th:each=\"item: ${array}\" th:text=\"${item}\">条目</li>\n" +
                "    </ul>\n" +
                "</body>\n" +
                "</html>";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("name", "蔬菜列表");
        params.put("array", new String[]{"土豆", "番茄", "白菜", "芹菜"});
        HtmlTemplateUtils.render(template, params);
    }
}
